﻿using System;
using Fjaspx.Common;
using System.IO;

namespace Fjaspx.UI.Web
{
    public partial class Administrator_user_edit_ss : AdminPage
    {

        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["uid"] != null)
                {
                    ShowInfo(Convert.ToInt32(Request["uid"]));
                }
            }
        }

        /// <summary>
        /// Shows the info.
        /// </summary>
        /// <param name="bh">The bh.</param>
        private void ShowInfo(int bh)
        {
            ___ROYcms_user_model = ___ROYcms_user_bll.GetModel(bh);
            this.txtname.Text = ___ROYcms_user_model.name;
            this.txtpassword.Text = ___ROYcms_user_model.password;
            this.txtqq.Text = ___ROYcms_user_model.qq;
            this.txtemail.Text = ___ROYcms_user_model.email;
            this.txtpic.Text = ___ROYcms_user_model.pic;
            this.txtusername.Text = ___ROYcms_user_model.username;
            if (___ROYcms_user_model.UgroupID != null && ___ROYcms_user_model.UgroupID != "")
            {
                try
                {
                    this.UGroup_DropDownList.SelectedValue = ___ROYcms_user_model.UgroupID;
                }
                catch {  //删除无效的用户组所属权限
                    ___ROYcms_user_bll.Update(___ROYcms_user_model.UgroupID); }
            }

        }

        /// <summary>
        /// Handles the Click event of the Edit control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Edit_Click(object sender, EventArgs e)
        {


            string strErr = "";
            if (this.txtname.Text == "")
            {
                strErr += "name不能为空！\\n";
            }
            if (this.txtpassword.Text == "")
            {
                strErr += "password不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }

            string name = this.txtname.Text;
            string password = this.txtpassword.Text;

            string qq = this.txtqq.Text;
            string email = this.txtemail.Text;

            DateTime login_time = DateTime.Now;
            string pic = this.txtpic.Text;
            string username = this.txtusername.Text;

            if (Request["uid"] != null)
            {
                ___ROYcms_user_model.bh = Convert.ToInt32(Request["uid"]);
            }

            ___ROYcms_user_model.name = name;
            ___ROYcms_user_model.password = password;
            ___ROYcms_user_model.qq = qq;
            ___ROYcms_user_model.email = email;
            ___ROYcms_user_model.age = 0;
            ___ROYcms_user_model.pic = pic;
            ___ROYcms_user_model.quanxian = "Guest";
            if (this.UGroup_DropDownList.SelectedValue != "")
            {
                ___ROYcms_user_model.UgroupID = this.UGroup_DropDownList.SelectedValue;
            }
            ___ROYcms_user_model.RoleID = "0";
            ___ROYcms_user_model.username = username;

            ___ROYcms_user_bll.Update(___ROYcms_user_model);

            Response.Redirect("user.aspx");
        }

    }
}